package com.tdd.common;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author xiaoxiyuan
 * @description 编码器
 * @date 2020-06-11 15:28:41
 */
public class MessageEncoder extends MessageToByteEncoder<MessageProtocol> {

    @Override
    protected void encode(ChannelHandlerContext ctx, MessageProtocol messageProtocol, ByteBuf out) throws Exception {
        System.out.println("MessageEncoder encode 方法被调用");
        out.writeInt(messageProtocol.getLen());
        out.writeBytes(messageProtocol.getContent());
    }
}
